import axios from "axios"
import api from './index'
// 接口1：管理员登录
export const singin = async (data={})=> {
    return axios.post(
        `${api.url}/api/user/signin`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口2：验证码
export const test = async (data={})=> {
    return axios.get(
        `${api.url}/api/verify/test`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口3: 用户列表
export const userList = async (data={})=> {
    return axios.get(`${api.url}/api/user/list`, {params: data}).then(response => response.data)
}

// 接口4：添加分类
export const categoryAdd = async (data={})=> {
    return axios.post(
        `${api.url}/api/exam/category_add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口5： 获取分类列表
export const categoryList = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/category_list`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口6： 删除分类
export const categoryRemove = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/category_remove`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口7：上传图片
export const photoUpload = async (data={})=> {
    return axios.post(
        `${api.url}/api/photo/upload`, 
         data,
         {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }
    )
    .then(response => response.data)
}
// 接口8：删除图片
export const photoDelete = async (data={})=> {
    return axios.post(
        `${api.url}/api/photo/delete`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口9：发布详情
export const examAdd = async (data={})=> {
    return axios.post(
        `${api.url}/api/exam/exam_add`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}

// 接口10：日期管理
export const examList = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/exam_list_all`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口11：删除日期
export const examRemove = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/exam_remove`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口12：获取列表
export const examItems = async (data={})=> {
    return axios.get(
        `${api.url}/api/exam/exam_items`, 
         {
            params: data
         } 
    )
    .then(response => response.data)
}

// 接口：账号信息
export const getAccountInfo = async (data={})=> {
    return axios.post(
        `${api.url}/api/user/info`, 
         data,
         {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    )
    .then(response => response.data)
}


// 接口: 使用第三方API获取账号登录IP地址
export const getIpAdress = async ()=> {
    return axios.get(
        'http://ip-api.com/json'
    )
    .then(response => response.data)
    .catch(error => {
        console.error('无法获取IP地址信息：', error);
    });
}